<template>
	<view class="claim-order-collage-list">
		<fixed>
			<view class="fill-base pd-lg f-paragraph c-title b-1px-b">我参与了{{list.total_num||0}}个众筹</view>
			<tab @change="handerTabChange" :list="tabList" :activeIndex="activeIndex" :activeColor="primaryColor"
				:width="100/tabList.length + '%'" height="100rpx"></tab>
			<view class="b-1px-b"></view>
		</fixed>
		<view @tap.stop="goDetail(index)" class="order-item rel fill-base mg-big pd-lg radius-16"
			v-for="(item,index) in list.data" :key="index">
			<view class="flex-between pb-lg f-desc b-1px-b" :style="{color:primaryColor}"
				v-if="activeIndex==0 && item.status==1">
				<view> 距离开团结束仅剩 </view>
				<min-countdown :type="2" :targetTime="item.end_time * 1000" :color="primaryColor"
					:textColor="primaryColor" :borderColor="primaryColor" @callback="countEnd">
				</min-countdown>
			</view>
			<view class="pb-lg f-sm-title c-title text-bold" :class="[{'pt-lg':activeIndex==0 && item.status ==1}]">
				{{item.claim_title}}
			</view>
			<view class="flex-center">
				<view class="flex-warp flex-1">
					<block v-for="(aitem,aindex) in item.user_avatar" :key="index">
						<view class="avatar-group md" v-if="aindex<4">
							<image mode="aspectFill" lazy-load class="abs avatar fill-body radius" :src="aitem">
							</image>
						</view>
					</block>
				</view>
				<view class="common-btn flex-center f-desc c-base" :style="{background:primaryColor}"
					v-if="activeIndex==1">查看订单</view>
			</view>
			<view class="collage-status-icon abs iconfont icon-biaoqian flex-center"
				:style="{color:item.status==1?primaryColor:'#E82F21'}" v-if="activeIndex==0">
				<view class="f-icontext text-bold abs">{{statusType[item.status]}}</view>
			</view>
		</view>

		<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading" v-if="loading">
		</load-more>
		<abnor v-if="!loading&&list.data.length<=0&&list.current_page==1"></abnor>

		<view class="space-footer"></view>
		<common-popup @confirm="confirmCancel" ref="cancel_item" type="CANCEL_ORDER" :info="popupInfo"></common-popup>
	</view>
</template>

<script>
	import {
		mapState,
	} from "vuex"
	export default {
		components: {},
		data() {
			return {
				options: {},
				activeIndex: 0,
				tabList: [{
					id: 1,
					title: '未成团'
				}, {
					id: 2,
					title: '已成团'
				}],
				statusType: {
					1: '进行中',
					2: '众筹成功',
					3: '众筹超时'
				},
				param: {
					page: 1,
				},
				list: {
					data: []
				},
				loading: true,
				popupInfo: {},
				lockTap: false
			}
		},
		computed: mapState({
			primaryColor: state => state.config.configInfo.primaryColor,
			subColor: state => state.config.configInfo.subColor,
			configInfo: state => state.config.configInfo,
			userInfo: state => state.user.userInfo,
		}),
		onLoad(options) {
			this.$util.showLoading()
			this.options = options
			let {
				tab = 0
			} = options
			this.activeIndex = tab
			this.initIndex()
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.list.current_page >= this.list.last_page || this.loading) return
			this.param.page = this.param.page + 1
			this.loading = true
			this.getList()
		},
		methods: {
			initIndex() {
				this.getList()
			},
			initRefresh() {
				this.param.page = 1
				this.initIndex()
			},
			countEnd() {
				this.$util.log("倒计时完了")
				setTimeout(() => {
					this.initRefresh()
				}, 1000)
			},
			handerTabChange(index) {
				this.activeIndex = index
				this.$util.showLoading()
				this.param.page = 1
				this.list.data = []
				this.getList()
			},
			async getList() {
				let {
					list: oldList,
					param,
					tabList,
					activeIndex
				} = this
				param.status = tabList[activeIndex].id
				let newList = await this.$api.claim.userCollageList(param);
				if (this.param.page == 1) {
					this.list = newList
				} else {
					newList.data = oldList.data.concat(newList.data)
					this.list = newList
				}
				this.loading = false
				this.$util.hideAll()
			},
			// 订单详情
			goDetail(index) {
				let {
					start_id,
					order_id
				} = this.list.data[index]
				let {
					activeIndex
				} = this
				let url = activeIndex == 0 ? `/claim/pages/order/collage/detail?id=${start_id}` :
					`/claim/pages/order/detail?id=${order_id}`
				this.$util.goUrl({
					url
				})
			}
		}
	}
</script>


<style lang="scss">
	.claim-order-collage-list {

		.order-item {
			.collage-status-icon {
				right: 30rpx;
				bottom: 30rpx;
				width: 110rpx;
				height: 100rpx;
				font-size: 100rpx;

				.text-bold {
					height: 26rpx;
					transform: rotate(-32deg);
				}
			}

		}
	}
</style>
